Scripting Tutorial: Introduction



Before we begin I'd like to tell you what all you will learn from this tutorial and what not. This tutorial was written specially for people who have never scripted in mIRC whether you have programming experience in other languages or not. Primarily it covers Aliases, Popups, Identifiers, Commands, Variables, Operators, Statements, Remote, CTCP, Raw and Access Levels in mIRC. It doesn't deal with more advanced topic like Sockets, Picture Windows, DLLS, Dialog boxes etc. If you are interested in a tutorial by me on those topics you will have to wait till I finish another of my tutorials titled "Advanced mIRC Scripting". Till then read on this one and master all I have got to show you.

The mIRC script syntax is very similar to Bash shell script, JavaScript, Perl, C++ and Java. So people who have had experiences programming in those languages will have a quicker grasp of the language than a total newbie. Even if not specifically those languages, anybody who has programmed in any language and gets the logic of the use of if-then-else and operators won't need to learn their use again in mIRC. I'd like to remind all the typed language programmers that mIRC script is not typed at all and you don't terminate your statements with semicolons. Forget this and your script won't work.

If you are totally new to mIRC scripting and have no idea how and where to begin, here's help. First of all we'll see what the mIRC Scripts Editor is. It's where you write your scripts. Refer the picture below:

You click on the icon pointed by the cursor in the picture to open the mIRC Scripts Editor in mIRC v6.15. If you are using an older version it will look different though. I am writing this tutorial with version 6.15 in mind. If you are using an older version you will need to download and install version 6.15. It's not a huge file; only 1.23 Mb. So you can always do it.


The picture on the right shows the mIRC Scripts Editor. It's in the Aliases editing mode. The other modes are Popups, Remotes, Users and Variables. You change the mode by clicking on the corresponding Tabs. I'll be using the words work space, panel and editing mode interchangeably.

Many script files can be loaded onto the editor at a given time. For example: 3 Alias scripts, 2 Popup scripts and 5 Remote scripts. Now how do you edit the files individually? Click on View and select the script you wanna edit. Make sure you are in the proper edit mode or you won't find your files. Writing a script in the wrong mode will make your script not function at all. You should be in the correct mode - look at the active tab.

The picture on the right shows the View menu. It's in the Remote edit mode. You can observe: 5 files are loaded and spmail.mrc is the currently the active file in the edit mode. So you get the idea.

To create a new script file you click on File>New. To load a file, File>Load. If you have ever used NotePad you should get the logic of how things work. The File commands are similar. Only make sure when you click Unload, the intended script file is selected in the editor. It's a common mistake which happens esp if you are in a hurry. You often end up unloading the wrong file. As a newbie you should take special care.

Now a brief introduction about Aliases, Popups and Remote. Wondering why I didn't include User and Variables? Because they contain values to be usually created and used by the 'active' scripts (Aliases, Popups and Remote). I never use Users, I find it boring =:) It's just my personal preference and scripting style. You can definitely do without it. Variables, you don't usually write a special Variables file. Maybe some people do. But I don't. I create the variables from the scripts itself. If I have to use a lot of Variable values I usually use an INI file. You can forget about all these for now. Just remember it's the Alias, Popup and Remote which you use to create mIRC script files. Now let's take a look what they are.

Aliases:
Typing /j #channel makes you join #channel. /op NickName will set NickName mode +o. Type /p #channel and you part the channel #chanel. They are examples of Aliases. Let's say you have a robot called CleaningLady. When you whistle Am she closes the windows. When you whistle G# she closes the door. When you whistle F she brings you a can of beer and plays 'The Party Song' by Blink-182. Now, you see you have used whistle notes to invoke predefined actions which would have otherwise taken you more than one word to express your will. Aliases have a similar function, they help you customize your short-cuts (or long-cuts if you are not very bright) for mIRC commands. You didn't have to type /join #channel or /part #channel or /mode #channel +o NickName, which are the actual mIRC commands. We'll see more about Aliases in the Chapter on Aliases.

Popups:
That's what a Popup is, the picture at the right. You get that particular one when you right click in the query window (private message window). Aliases and Popups are very similar in function. Popups too are used to create (clickable) shortcuts. In Aliases you had to know the alias you created to envoke it. In Popups you are presented with the shortcuts you created when you RightClick the mouse. Analogy: You have a poster in your room with many words listed on it. When you point on "Pizza" CleaningLady brings you a Pizza. When you point on "Pizza-o" she cleans up all the Pizza mess you created on your table. When you point on "Pizza-p" she brings you a Pizza and a Pepsi. See, you save a lot of time and energy by not having to explain CleaningLady in detail again and again what you want. Popups are often used to call (envoke) the aliases you created. We'll see more about Popups in the Popups chapter.

Remote:
This is the ultimate one. Apart from it's native functions it can be used to create both Aliases and Popups. And yes also custom Identifiers, things like $cleaninglady(). Cool huh? We'll see more about Identifiers and custom Identifiers later. If you plan to distribute your scripts, I suggest you use Remote to create Aliases and Popups. Let's take a look at the native functions of Remotes. You must have seen or heard about scripts that will automatically voice (mode +v) the people who join the channel. Or those which will close the query window if the text contains www. They are all Remote based: If something happens, then do this or that. As long as the event you specified doesn't take place the commands are not executed. CleaningLady won't clean your room as long as it is clean, she won't feed you as long as you are not hungry, she won't bath you as long as you are not stinking like a Yeti. But at the same time you should have programed her to do the necessary when the condition is true. Remote is a compartively vast topic and a very very interesting one. More about Remotes in the Remotes chapter.

Before I forget, I wanna tell you about comments. Comments are anything else you write in your code you don't mIRC to interpret during execution. You may need to use them in your script to remember which part of the program does what, especially if your program becomes too lenghty and complex. When you look at your codes after some period of time it's usually hard to figure out what's going on. Or maybe to include author and contact information in your script. mIRC v6.12 and later supports two types of comments: ; and /* */. Examples are given below.

Example 1:

; Echo Script v1.0
; Author: Scripter-Boi
; E-mail: scripter-boi@scripter-boi.com

alias /en /echo -a My nick is $me

; EOF
Example 2:
/* This is my first super cool program. I have put a lot of effort and time on it.
   So I request you not to rip it.
   If you like it. You can mail me at scripter-boi@scripter-boi.com
*/

; Echoes the nick
alias /en /echo -a My nick is $me

; Echoes the time
alias /et /echo -a The time is now $time

; EOF
Note: When using single line comments, make sure the comments always preceed the codes. mIRC doesn't support post-code comments like other programming langaguages.

You wanna test and debug your remote online scripts without being connected to the Internet? Yes, you can do that - just run your own IRC server and connect to it. A good one is Beware IRCd. It's only 169 Kb and quite impressive in performance. Find it in the Resources section. Once you get it running type /server 127.0.0.1 or /server localhost in mIRC to connect.

If you are a really really clueless newbie you may have no idea how to load an mIRC script file too. Just in case, I'll tell you how to do that. You know there are many types of script files and you need to load them appropriately or they won't work. Most of the scripts you get online are Remote scripts so you will be using the /load -rs <filename> most often. As you might have guessed you use the load command to load the scripts. Below I show you how to load the different scripts in their appropriate ways.

/load -a <filename>   Loads an Aliases file.
/load -pc <filename> Loads a channel Popup file.
/load -pn <filename> Loads a nicklist Popup file.
/load -rs <filename> Loads a Remote file.
/load -ru <filename> Loads a Users file.
/load -rv <filename> Loads a Variables file.

That was the way to load the script files from the command line. There's another way to load scripts in mIRC - from the mIRC Editor. First select the panel where you want to load the file. If it's a Remote script the active panel in the mIRC Editor should be Remote and likewise for other script types. Then you click on File > Load, browse for the file and select it.

To unload the files from the command line you use the unload command with the appropriate switches and the file name to unload. For example if you want to unload a Remote file named test.mrc you use the command /unload -rs test.mrc. From the mIRC Editor you unload a script by bringing it in the editing mode (it should be the active script in the mIRC Editor) and then go to File menu and click on Unload.

Now that you've gotten some idea about the mIRC Scripts Editor, Aliases, Popups, Remotes and Comments we can begin with the Tutorial. It's often necessary that you learn two or more things at the same time to be able to write interesting scripts as a beginner. So a strict step by step learning process won't help you much. It'd be really helpful to your progress if you learnt about identifiers and commands on your own and right from the start. I won't be discussing in detail about Identifiers and Commands because everything is there in the Help File already. Are we ready? Let's start with Aliases.


Table of Contents | Aliases



Copyright © 2002-2004 SpyderWares.
Feel free to distribute this tutorial in part or whole, just make sure the credits stay intact.

http://spyderwares.com